package com.common.boot.controller.system;

import com.common.boot.exception.ExceptionStatus;
import com.common.boot.service.ImageService;
import com.common.boot.util.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 图片接口
 */
@Slf4j
@RestController
@RequestMapping("/img")
public class ImageController {

    @Autowired
    private ImageService imageService;

    /**
     * 上传图片
     * @param multipartFile
     * @param request
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/ngUploadImg", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult ngUploadImg(MultipartFile multipartFile, HttpServletRequest request) {
        try {
            return new ResponseResult(imageService.ngUploadImg(multipartFile,request));
        }catch (Exception e){
            log.error("请求错误",e);
            return new ResponseResult(ExceptionStatus.INFO_FAIL);
        }
    }

}
